package com.zw.knowlege.pojo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zw.common.constant.ExperienceStatusEnum;
import com.zw.knowlege.common.StaticValue;
import com.zw.knowlege.util.CommonUtils;
import lombok.Data;
import lombok.Getter;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

public class ExperiencePojo {
    /**
     * 经验编码，区分唯一
     */
    private String experienceid;
    /**
     * 经验标题
     */
    private String experiencetitle;
    /**
     * 部门
     */
    private String deptname;
    /**
     * 用户id
     */
    private String userid;
    /**
     * 用户名
     */
    private String username;
    /**
     * 案件类型
     */
    private String[] classinfo;
    /**
     * 部门类型
     */
    private String[] depttype;
    /**
     * 描述
     */
    private String description;
    /**
     * 法规引用名称
     */
    private String legalrefname;
    /**
     * 法规引用URL
     */
    private String legalrefurl;
    /**
     * 关联案例ID
     */
    private String[] relatecaseid;
    /**
     * 处置方法
     */
    private String handmethod;
    /**
     * 注意事项
     */
    private String[] attention;
    /**
     * 备注
     */
    private String remark;
    /**
     * 创建时间
     */
    private Timestamp createtime;
    /**
     * 更新时间
     */
    private Timestamp updatetime;
    /**
     * 状态
     */
    private Integer status;
    /**
     * 上一版本的ID
     */
    private String historyid = "";
    /**
     * 收藏次数
     */
    private Integer collectcount;
    /**
     * 动作类型
     */
    private String action;
    /**
     * 是否发布过
     */
    private Integer isrelease = 0;
    /**
     * 发布的版本
     */
    private Integer version = 1;
    /**
     * 版本列表，按照创建时间倒叙排列
     *
     */
    private List<Map<String, Object>> versionList;
    /**
     * 用于标注该经验是否收藏
     */
    private boolean isCollect = false;

    public ExperiencePojo setExperienceid(String experienceid) {
        this.experienceid = CommonUtils.nullOrEmpty(experienceid) ? CommonUtils.getMd5(this.toString()) : experienceid;
        return this;
    }
    public ExperiencePojo setExperiencetitle(String experiencetitle) {
        this.experiencetitle = experiencetitle;
        return this;
    }

    public ExperiencePojo setDeptname(String deptname) {
        this.deptname = deptname;
        return this;
    }

    public ExperiencePojo setUserid(String userid) {
        this.userid = userid;
        return this;
    }

    public ExperiencePojo setUsername(String username) {
        this.username = username;
        return this;
    }

    public ExperiencePojo setClassinfo(JSONArray classinfoJsonArray) {
        this.classinfo = classinfoJsonArray.toArray(new String[classinfoJsonArray.size()]);
        return this;
    }

    public void setClassinfo(String[] classinfo) {
        this.classinfo = classinfo;
    }

    public ExperiencePojo setDepttype(JSONArray depttypeJsonArray) {
        this.depttype = depttypeJsonArray.toArray(new String[depttypeJsonArray.size()]);
        return this;
    }

    public void setDepttype(String[] depttype) {
        this.depttype = depttype;
    }

    public ExperiencePojo setDescription(String description) {
        this.description = description;
        return this;
    }

    public ExperiencePojo setLegalrefname(String legalrefname) {
        this.legalrefname = legalrefname;
        return this;
    }

    public ExperiencePojo setLegalrefurl(String legalrefurl) {
        this.legalrefurl = legalrefurl;
        return this;
    }

    public ExperiencePojo setRelatecaseid(JSONArray relatecaseIdJsonArray) {
        if(null != relatecaseIdJsonArray && !relatecaseIdJsonArray.isEmpty()){
            this.relatecaseid = relatecaseIdJsonArray.toArray(new String[relatecaseIdJsonArray.size()]);
        }
        return this;
    }

    public ExperiencePojo setHandmethod(String handmethod) {
        this.handmethod = handmethod;
        return this;
    }

    public ExperiencePojo setAttention(JSONArray attentionJsonArray) {
        if(null != attentionJsonArray && !attentionJsonArray.isEmpty()){
            this.attention = attentionJsonArray.toArray(new String[attentionJsonArray.size()]);
        }
        return this;
    }

    public ExperiencePojo setRemark(String remark) {
        this.remark = remark;
        return this;
    }

    public ExperiencePojo setCreatetime() {
        this.createtime = new Timestamp(System.currentTimeMillis());
        return this;
    }

    public ExperiencePojo setUpdatetime(Timestamp updatetime) {
        this.updatetime = updatetime;
        return this;
    }


    public ExperiencePojo setStatus(Integer status) {
        this.status = status;
        return this;
    }
    public ExperiencePojo setStatus() {
        this.status = StaticValue.EXPERIENCE_ACTION_RELEASE.equals(this.action) ? 1 : 0;
        return this;
    }
    public ExperiencePojo setHistoryid() {
        this.historyid = this.experienceid;
        return this;
    }

    public ExperiencePojo setCollectcount(Integer collectcount) {
        this.collectcount = collectcount;
        return this;
    }

    public ExperiencePojo setAction(String action) {
        this.action = action;
        return this;
    }

    /**
     * 解析用户信息
     * @param userinfoParam
     * @return
     */
    public ExperiencePojo parseUserinfo(JSONObject userinfoJson){
        this.setDeptname(userinfoJson.getString(StaticValue.EXPERIENCE_USERINFO_DEPTNAME));
        this.setUserid(userinfoJson.getString(StaticValue.EXPERIENCE_USERINFO_USERID));
        this.setUsername(userinfoJson.getString(StaticValue.EXPERIENCE_USERINFO_USERNAME));
        return this;
    }

    public ExperiencePojo setIsrelease() {
        this.isrelease = StaticValue.EXPERIENCE_ACTION_RELEASE.equals(this.action) ? ExperienceStatusEnum.RELEASED.getStatus() : ExperienceStatusEnum.UPDATED.getStatus();
        return this;
    }

    public ExperiencePojo setVersion(Integer version) {
        this.version = version;
        return this;
    }

    public String getExperienceid() {
        return experienceid;
    }

    public String getExperiencetitle() {
        return experiencetitle;
    }

    public String getDeptname() {
        return deptname;
    }

    public String getUserid() {
        return userid;
    }

    public String getUsername() {
        return username;
    }

    public String[] getClassinfo() {
        return classinfo;
    }

    public String[] getDepttype() {
        return depttype;
    }

    public String getDescription() {
        return description;
    }

    public String getLegalrefname() {
        return legalrefname;
    }

    public String getLegalrefurl() {
        return legalrefurl;
    }

    public String[] getRelatecaseid() {
        return relatecaseid;
    }

    public void setRelatecaseid(String[] relatecaseid) {
        this.relatecaseid = relatecaseid;
    }

    public String getHandmethod() {
        return handmethod;
    }

    public String[] getAttention() {
        return attention;
    }

    public void setAttention(String[] attention) {
        this.attention = attention;
    }

    public String getRemark() {
        return remark;
    }

    public Timestamp getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Timestamp createtime) {
        this.createtime = createtime;
    }

    public Timestamp getUpdatetime() {
        return updatetime;
    }

    public Integer getStatus() {
        return status;
    }

    public String getHistoryid() {
        return historyid;
    }

    public void setHistoryid(String historyid) {
        this.historyid = historyid;
    }

    public Integer getCollectcount() {
        return collectcount;
    }

    public String getAction() {
        return action;
    }

    public Integer getIsrelease() {
        return isrelease;
    }

    public void setIsrelease(Integer isrelease) {
        this.isrelease = isrelease;
    }

    public Integer getVersion() {
        return version;
    }

    public List<Map<String, Object>> getVersionList() {
        return versionList;
    }

    public void setVersionList(List<Map<String, Object>> versionList) {
        this.versionList = versionList;
    }

    public boolean isCollect() {
        return isCollect;
    }

    public void setCollect(boolean collect) {
        isCollect = collect;
    }

    @Override
    public String toString() {
        return "ExperiencePojo{" +
                "experienceid='" + experienceid + '\'' +
                ", experiencetitle='" + experiencetitle + '\'' +
                ", deptname='" + deptname + '\'' +
                ", userid='" + userid + '\'' +
                ", username='" + username + '\'' +
                ", classinfo=" + Arrays.toString(classinfo) +
                ", depttype=" + Arrays.toString(depttype) +
                ", description='" + description + '\'' +
                ", legalrefname='" + legalrefname + '\'' +
                ", legalrefurl='" + legalrefurl + '\'' +
                ", relatecaseid=" + Arrays.toString(relatecaseid) +
                ", handmethod='" + handmethod + '\'' +
                ", attention=" + Arrays.toString(attention) +
                ", remark='" + remark + '\'' +
                ", createtime=" + createtime +
                ", updatetime=" + updatetime +
                ", status=" + status +
                ", historyid='" + historyid + '\'' +
                ", collectcount=" + collectcount +
                ", action='" + action + '\'' +
                ", isrelease=" + isrelease +
                ", version=" + version +
                ", versionList=" + versionList +
                ", isCollect=" + isCollect +
                '}';
    }
}